package cn.sinjet.adapter;

import java.util.List;

import com.mgroup.wazehelper.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import cn.sinjet.entity.AppInfo;

/**
 * @author Kevin
 */
public class ShortcutAdapter extends BaseAdapter {
	private Context mContext;
	private List<AppInfo> mList = null;
	private LayoutInflater inflater;
	public ShortcutAdapter(List<AppInfo> list, Context context) {
		mList = list;
		mContext = context;
		inflater = LayoutInflater.from(mContext);	
	}

	public void setListItem(List<AppInfo> list){
		mList = list;
	}
	@Override
	public int getCount() {
		if(mList != null)
		return mList.size();
		return 0;
	}

	@Override
	public Object getItem(int position) {
		if(mList == null || position > mList.size())
			return null;
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if(convertView == null){
			convertView = inflater.inflate(R.layout.app_info_item, null);
			holder = new ViewHolder();
			holder.appIcon = (ImageView)convertView.findViewById(R.id.app_icon);
			holder.appName = (TextView)convertView.findViewById(R.id.app_name);
//			holder.packageName = (TextView) convertView.findViewById(R.id.road_info);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		holder.appIcon.setImageDrawable(mList.get(position).appIcon);
		holder.appName.setText(mList.get(position).appName);
//		holder.packageName.setText(mList.get(position).packageName);
		return convertView;
	}
	
	public static class ViewHolder {
		TextView  appName;
//		TextView  packageName;
		ImageView appIcon;
	}
}
